package com.user.command;

import org.apache.ibatis.session.SqlSession;

import com.user.applaction.SessionManager;
import com.user.applaction.UserApp;
import com.user.mapping.UserMapping;
import com.user.tool.Tool;
/**
 * 注册命令（signup）
 * @author sunchengqi
 *
 */
public class SignupCommand implements Command {
	@Override
	public void excute() {
		SqlSession session = SessionManager.getInstance().getSession();
		UserMapping mapper = session.getMapper(UserMapping.class);
		//输入非空值的帐号信息
		UserApp.getUser().setUserId(Tool.askUserInputNotNull("创建账号"));
		UserApp.getUser().setUserPassword(Tool.askUserInputNotNull("创建密码"));
		//执行插入，插入返回影响好行数大于0注册成功，否则打印失败信息
		if ((mapper.insertWithoutId(UserApp.getUser())) > 0) {
			Tool.printMsg("注册成功");
		} else {
			Tool.printMsg("注册失败，账户已存在");
		}
		//
		session.commit();
		session.close();
	}

}
